package com.xxcloud.web.note.controller;

import javax.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xxcloud.model.exception.note.NoteException;
import com.xxcloud.model.web.JsonResult;
import com.xxcloud.model.web.note.dto.NoteDTO;
import com.xxcloud.model.web.note.vo.NoteVO;
import com.xxcloud.service.note.INoteService;
import com.xxcloud.web.base.controller.BaseController;
import io.swagger.annotations.ApiOperation;

/**
 * Created by chenbingwen on 19/10/29.
 */
@RestController
@RequestMapping("note")
public class NoteController extends BaseController {

    @Resource(name = "noteService")
    private INoteService noteService;

    @ApiOperation(value = "笔记详情", notes = "笔记详情")
    @GetMapping("{noteId}/note.json")
    public JsonResult noteDetail(@PathVariable("noteId") long noteId) {
        NoteVO result = noteService.getNoteDetail(noteId);
        return JsonResult.getResult(result);
    }

    @ApiOperation(value = "新增/修改笔记", notes = "新增/修改笔记")
    @PostMapping("note.json")
    public JsonResult upsertNote(@ModelAttribute NoteDTO dto) throws NoteException {
        setUserId(dto);
        boolean result = noteService.upsertNote(dto);
        return JsonResult.getResult(result);
    }
}
